import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { ResourceType } from './resource-type';
import { RESOURCE_TYPE } from './typs';
import { pb } from '../../pb';

@Component({
  selector: 'app-resources',
  templateUrl: './resources.page.html',
  styleUrls: ['./resources.page.scss'],
})
export class ResourcesPage implements OnInit {
  resources: pb.Resource[] = [];
  type: ResourceType;
  constructor(private activatedRoute: ActivatedRoute) {
    this.resources.push(pb.Resource.create({
      id: 1,
      type: pb.Resource.Type.IMAGES,
      title: '蛋糕',
      note: '一块美味的蛋糕',
      url: 'http://p8.qhimg.com/bdm/1024_768_85/t01ae57e7e6f98862d0.jpg',
    }))
    this.resources.push(pb.Resource.create({
      id: 2,
      type: pb.Resource.Type.IMAGES,
      title: '雪山',
      note: '壮观的大雪山',
      url: 'http://browser9.qhimg.com/bdm/1024_768_85/t016ad88ddaf2ae2d92.jpg',
    }))
  }

  ngOnInit() {
    const type = this.activatedRoute.snapshot.paramMap.get('type');
    for (const t of RESOURCE_TYPE) {
      if (t.type == type) {
        this.type = t;
      }
    }
  }
}
